package svc

import (
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"github.com/zeromicro/go-zero/zrpc"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/app/rpc/model/pg/wallet"
	"navi-mumbai/app/rpc/model/redis/user"
	"navi-mumbai/app/rpc/usercenter/internal/config"
	"navi-mumbai/app/rpc/wallet/client/walletsys"
	"navi-mumbai/third/appsflyer"
)

type ServiceContext struct {
	Config      config.Config
	RedisClient *redis.Redis

	UserAccountModel             usercenter.UserAccountModel
	UserLoginStatModel           usercenter.UserLoginStatModel
	UserBanModel                 usercenter.UserBanModel
	UserProfileModel             usercenter.UserProfileModel
	UserFeedbackModel            usercenter.UserFeedbackModel
	UserNotifyMsgModel           usercenter.UserNotifyMsgModel
	UserNotifyMsgStatModel       usercenter.UserNotifyMsgStatModel
	AppConfigModel               usercenter.AppConfigModel
	UserRewardModel              usercenter.UserRewardModel
	UserRewardStatModel          usercenter.UserRewardStatModel
	UserPayAccountAddressModel   usercenter.UserPayAccountAddressModel
	BannerConfigModel            usercenter.BannerConfigModel
	UserRewardLimitModel         usercenter.UserRewardLimitModel
	UserApkConfigModel           usercenter.ApkConfigModel
	ActivityConfigModel          usercenter.ActivityConfigModel
	UserServiceUpdateConfigModel usercenter.ServiceUpdateConfigModel
	MarqueeConfigModel           usercenter.MarqueeConfigModel
	UserInviteConfigModel        usercenter.UserInviteConfigModel
	UserInviteModel              usercenter.UserInviteModel
	UserInviteOrderFlowModel     usercenter.UserInviteOrderFlowModel
	UserInviteDeviceModel        usercenter.UserInviteDeviceModel
	UserWalletModel              wallet.UserWalletModel

	WalletSysRpc       walletsys.WalletSys
	UserVerifyLogModel usercenter.UserVerifyLogModel

	UserRedis *user.UserRedis

	//KqAddUserNotifyMsgClient *kq.Pusher
	//KqAddUserRewardClient    *kq.Pusher
	//KqAddUserLoginLogClient  *kq.Pusher
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlConn := sqlx.NewMysql(c.DB.DataSource)
	sqlWalletConn := sqlx.NewMysql(c.WalletReadDB.DataSource)
	//sqlConn := sqlx.NewSqlConn(dbkey.PostgresDriverName, c.DB.DataSource)
	appsflyer.InitHttpServer()
	sc := ServiceContext{
		Config:                       c,
		UserAccountModel:             usercenter.NewUserAccountModel(sqlConn, c.Cache),
		UserLoginStatModel:           usercenter.NewUserLoginStatModel(sqlConn, c.Cache),
		UserBanModel:                 usercenter.NewUserBanModel(sqlConn, c.Cache),
		UserProfileModel:             usercenter.NewUserProfileModel(sqlConn, c.Cache),
		UserFeedbackModel:            usercenter.NewUserFeedbackModel(sqlConn, c.Cache),
		UserNotifyMsgModel:           usercenter.NewUserNotifyMsgModel(sqlConn, c.Cache),
		UserNotifyMsgStatModel:       usercenter.NewUserNotifyMsgStatModel(sqlConn, c.Cache),
		AppConfigModel:               usercenter.NewAppConfigModel(sqlConn, c.Cache),
		UserRewardModel:              usercenter.NewUserRewardModel(sqlConn, c.Cache),
		UserRewardStatModel:          usercenter.NewUserRewardStatModel(sqlConn, c.Cache),
		UserPayAccountAddressModel:   usercenter.NewUserPayAccountAddressModel(sqlConn, c.Cache),
		BannerConfigModel:            usercenter.NewBannerConfigModel(sqlConn, c.Cache),
		UserRewardLimitModel:         usercenter.NewUserRewardLimitModel(sqlConn, c.Cache),
		UserApkConfigModel:           usercenter.NewApkConfigModel(sqlConn, c.Cache),
		UserServiceUpdateConfigModel: usercenter.NewServiceUpdateConfigModel(sqlConn, c.Cache),
		MarqueeConfigModel:           usercenter.NewMarqueeConfigModel(sqlConn, c.Cache),
		UserVerifyLogModel:           usercenter.NewUserVerifyLogModel(sqlConn, c.Cache),
		ActivityConfigModel:          usercenter.NewActivityConfigModel(sqlConn, c.Cache),
		UserInviteConfigModel:        usercenter.NewUserInviteConfigModel(sqlConn, c.Cache),
		UserInviteModel:              usercenter.NewUserInviteModel(sqlConn, c.Cache),
		UserWalletModel:              wallet.NewUserWalletModel(sqlWalletConn, c.Cache),
		UserInviteOrderFlowModel:     usercenter.NewUserInviteOrderFlowModel(sqlConn, c.Cache),
		UserInviteDeviceModel:        usercenter.NewUserInviteDeviceModel(sqlConn, c.Cache),
		WalletSysRpc:                 walletsys.NewWalletSys(zrpc.MustNewClient(c.WalletRpcConf)),

		//KqAddUserNotifyMsgClient: kq.NewPusher(c.KqAddUserNotifyMsgClientConf.Brokers, c.KqAddUserNotifyMsgClientConf.Topic),
		//KqAddUserRewardClient:    kq.NewPusher(c.KqAddUserRewardClientConf.Brokers, c.KqAddUserRewardClientConf.Topic),
		//KqAddUserLoginLogClient:  kq.NewPusher(c.KqAddUserLoginLogClientConf.Brokers, c.KqAddUserLoginLogClientConf.Topic),
	}

	sc.RedisClient = redis.MustNewRedis(c.Redis.RedisConf)
	sc.UserRedis = user.NewUserRedis(sc.RedisClient)
	return &sc
}
